$.showLoading();
thin.imports('/public/configure/conf.minfo.js', function() {
	factory.request('_mlike_get');
});

function __complete_mlikeget(res) {
	var round = '',
		industry = '',
		city = '';
	if(res.status == 200) {
		jude_minfo = true;
		var data = res.data,
			begin_money = '',
			end_money = '';
		for(var i in data) {
			$('#ipt-ml-' + i).val(data[i]);
			$('#btn-ml-' + i).find('.value-text').html(data[i]);
			(i == 'round') && (round = data[i]);
			(i == 'industry') && (industry = data[i]);
			(i == 'city') && (city = data[i]);
			(i == 'begin_money') && (begin_money = data[i]);
			(i == 'end_money') && (end_money = data[i]);
		}
		(begin_money != '' && end_money != '') && $('#btn-edit-price').find('.value-text').html(begin_money + '-' + end_money + '万元');
	} else {
		$.toptip(res.error, 'error');
	}
	thin.imports('/public/configure/conf.opts.js', function() {
		__getdata_opts.name = 'round';
		factory.request('_common_opts', ['round', round]);
		__getdata_opts.name = 'industry';
		factory.request('_common_opts', ['industry', industry]);
		__getdata_opts.name = 'city';
		factory.request('_common_opts', ['city', city]);
		setTimeout(function() {
			$.hideLoading();
		}, 1200);
	});
}

var __getdata_opts = {};

/*thin.imports('/public/configure/conf.opts.js', function() {
	__getdata_opts.name = 'round';
	factory.request('_common_opts', 'round');
	__getdata_opts.name = 'industry';
	factory.request('_common_opts', 'industry');
	__getdata_opts.name = 'city';
	factory.request('_common_opts', 'city');
});*/

$(function() {
	$('#btn-memberlike').on('click', function(e) {
		if($(this).hasClass('weui-btn_disabled')) return;
		submitMemberLike();
	});

	$('#submit-price').on('click', function(e) {
		var n_n = $('#ipt-ml-begin_money').val(),
			n_p = $('#ipt-ml-end_money').val();
		(n_n != '' && n_p != '') && $('#btn-edit-price').find('.value-text').html(n_n + '-' + n_p + '万元');
		$.closePopup();
	});

	$('#weuiAgree').on('change', function(e) {
		var ischecked = $(this).prop('checked');
		if(ischecked) {
			$('#btn-memberlike').removeClass('weui-btn_disabled').addClass('on');
		} else {
			$('#btn-memberlike').removeClass('on').addClass('weui-btn_disabled');
		}
	});
});

function __complete_opts(res, unkn) {
	if(res.status == 200) {
		$('#btn-ml-' + unkn[0]).on('click', function(e) {
			var e = e || window.event;
			e.stopPropagation();
			e.preventDefault();
			$(this).select('open');
			return false;
		}).select({
			title: "请选择",
			multi: true,
			items: res.data,
			input: unkn[1],
			onClose: function(res) {
				$('#btn-ml-' + unkn[0]).find('.value-text').html(res.data.titles);
				$('#ipt-ml-' + unkn[0]).val(res.data.titles);
			}
		});
	} else {
		// nothing
	}
}

var __getdata_mlikecomplete = {};

function submitMemberLike() {
	$('[id*=ipt-ml]').each(function(index) {
		var that = $(this),
			name_arr = that.attr('id'),
			name = name_arr.split('-')[2];
		__getdata_mlikecomplete[name] = that.val();
	});
	$.showLoading();
	//console.dir(__getdata_mlikecomplete);
	factory.request('_mlike_complete');
}

function __complete_mlikecomplete(res) {
	$.hideLoading();
	if(res.status == 201) {
		$.toast("信息完善成功", 960);
		setTimeout(function() {
			window.location.href = '/mobile/service/member';
		}, 800);
	} else {
		$.toptip(res.error, 'error');
	}
}